﻿using DevExpress.Utils;
using System;
using System.Windows.Forms;
using System.Globalization;

namespace Smart.Common
{
    public class clsOption
    {
        private static WaitDialogForm dlg = null;

        public static void CreateWaitDialog()
        {
            if (dlg == null)
            {
                dlg = new WaitDialogForm("Đang nạp dữ liệu ...", "Vui l\x00f2ng đợi trong gi\x00e2y l\x00e1t...");
            }
        }

        private static void dlg_FormClosing(object sender, FormClosingEventArgs e)
        {
            dlg = null;
        }

        public static void DoHide()
        {
            if (dlg != null)
            {
                dlg.FormClosing += new FormClosingEventHandler(clsOption.dlg_FormClosing);
                dlg.Close();
            }
        }

        ~clsOption()
        {
            if (dlg != null)
            {
                dlg.FormClosing += new FormClosingEventHandler(clsOption.dlg_FormClosing);
                dlg.Close();
            }
        }

        public static void SetWaitDialogCaption(string fCaption)
        {
            if (dlg != null)
            {
                dlg.Caption = fCaption;
            }
            else
            {
                dlg = new WaitDialogForm(fCaption, "Vui l\x00f2ng đợi trong gi\x00e2y l\x00e1t...");
            }
        }

        public class DateTime
        {
            private static Smart.Common.clsOption.FormatType m_DateFormatType = Smart.Common.clsOption.FormatType.Custom;
            private static string m_DateSaparator = CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator;
            private static int m_DayLength = 2;
            private static string m_FormatDate = "dd/MM/yyyy";
            private static int m_MonthLength = 2;
            private static int m_YearLength = 4;

            private static string GetDay(bool DateSaparator)
            {
                string str = "";
                for (int i = 0; i < m_DayLength; i++)
                {
                    str = str + "d";
                }
                if (DateSaparator)
                {
                    str = str + m_DateSaparator;
                }
                return str;
            }

            private static string GetMonth(bool DateSaparator)
            {
                string str = "";
                for (int i = 0; i < m_MonthLength; i++)
                {
                    str = str + "M";
                }
                if (DateSaparator)
                {
                    str = str + m_DateSaparator;
                }
                return str;
            }

            private static string GetYear(bool DateSaparator)
            {
                string str = "";
                for (int i = 0; i < m_YearLength; i++)
                {
                    str = str + "y";
                }
                if (DateSaparator)
                {
                    str = str + m_DateSaparator;
                }
                return str;
            }

            public static int DayLength
            {
                get
                {
                    return m_DayLength;
                }
                set
                {
                    m_DayLength = value;
                }
            }

            public static string Format
            {
                get
                {
                    string day;
                    string month;
                    string year;
                    if (m_DateFormatType == Smart.Common.clsOption.FormatType.DMY)
                    {
                        day = GetDay(true);
                        month = GetMonth(true);
                        year = GetYear(false);
                        m_FormatDate = (day.Length == 1) ? "" : (day + ((month.Length == 1) ? "" : month) + year);
                        if (m_FormatDate.Trim() == string.Empty)
                        {
                            m_FormatDate = "dd/MM/yyyy";
                        }
                        return m_FormatDate;
                    }
                    if (m_DateFormatType == Smart.Common.clsOption.FormatType.MDY)
                    {
                        day = GetDay(true);
                        month = GetMonth(true);
                        year = GetYear(false);
                        m_FormatDate = (month.Length == 1) ? "" : (month + ((day.Length == 1) ? "" : day) + year);
                        if (m_FormatDate.Trim() == string.Empty)
                        {
                            m_FormatDate = "MM/dd/yyyy";
                        }
                        return m_FormatDate;
                    }
                    if (m_DateFormatType == Smart.Common.clsOption.FormatType.YMD)
                    {
                        day = GetDay(false);
                        month = GetMonth(true);
                        year = GetYear(true);
                        m_FormatDate = (year.Length == 1) ? "" : (year + ((month.Length == 1) ? "" : month) + day);
                        if (m_FormatDate.Trim() == string.Empty)
                        {
                            m_FormatDate = "yyyy/MM/dd";
                        }
                        return m_FormatDate;
                    }
                    return m_FormatDate;
                }
                set
                {
                    m_DateFormatType = Smart.Common.clsOption.FormatType.Custom;
                    m_FormatDate = value;
                }
            }

            public static string FormatString
            {
                get
                {
                    return ("{0:" + Format + "}");
                }
            }

            public static Smart.Common.clsOption.FormatType FormatType
            {
                get
                {
                    return m_DateFormatType;
                }
                set
                {
                    m_DateFormatType = value;
                }
            }

            public static int MonthLength
            {
                get
                {
                    return m_MonthLength;
                }
                set
                {
                    m_MonthLength = value;
                }
            }

            public static string Saparator
            {
                get
                {
                    return m_DateSaparator;
                }
                set
                {
                    m_DateSaparator = value;
                }
            }

            public static int YearLength
            {
                get
                {
                    return m_YearLength;
                }
                set
                {
                    m_YearLength = value;
                }
            }
        }

        public enum FormatType
        {
            Custom,
            DMY,
            MDY,
            YMD
        }

        public class Number
        {
            private static int m_Decimals = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalDigits;
            private static string m_DecimalSymbol = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
            private static string m_DigitGroupSymbol = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator;
            private static string m_FormatNumber = "##,##0.###";
            private static string m_FrefixSymbol = "";
            private static string m_SuffixSymbol = "";

            public static int Decimals
            {
                get
                {
                    return m_Decimals;
                }
                set
                {
                    m_Decimals = value;
                }
            }

            public static string DecimalSymbol
            {
                get
                {
                    return m_DecimalSymbol;
                }
                set
                {
                    m_DecimalSymbol = value;
                }
            }

            public static string DigitGroupSymbol
            {
                get
                {
                    return m_DigitGroupSymbol;
                }
                set
                {
                    m_DigitGroupSymbol = value;
                }
            }

            public static string Format
            {
                get
                {
                    string str = "##,##0.";
                    for (int i = 0; i < m_Decimals; i++)
                    {
                        str = str + "#";
                    }
                    m_FormatNumber = m_FrefixSymbol + str + m_SuffixSymbol;
                    return m_FormatNumber;
                }
                set
                {
                    m_FormatNumber = value;
                }
            }

            public static string FormatString
            {
                get
                {
                    return ("{0:" + Format + "}");
                }
            }

            public static string FrefixSymbol
            {
                get
                {
                    return m_FrefixSymbol;
                }
                set
                {
                    m_FrefixSymbol = value;
                }
            }

            public static string PercentFormatString
            {
                get
                {
                    return ("{0:" + Format + "} %");
                }
            }

            public static string SuffixSymbol
            {
                get
                {
                    return m_SuffixSymbol;
                }
                set
                {
                    m_SuffixSymbol = value;
                }
            }
        }

        public class Parameter
        {
            private static string m_Manager = "Gi\x00e1m đốc";

            public static string Manager
            {
                get
                {
                    return m_Manager;
                }
                set
                {
                    m_Manager = value;
                }
            }
        }

        public class Regional
        {
            private static clsOption.FormatType m_DateFormatType = clsOption.FormatType.Custom;
            private static string m_DateSaparator = CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator;
            private static int m_Decimals = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalDigits;
            private static string m_DecimalSymbol = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
            private static string m_DigitGroupSymbol = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator;
            private static string m_FormatDate = "dd/MM/yyyy";
            private static string m_FormatNumber = "##,##0.###";
            private static bool m_IsMsgBoxResult = true;
            private static bool m_IsQuestion = true;

            public static clsOption.FormatType DateFormatType
            {
                get
                {
                    return m_DateFormatType;
                }
                set
                {
                    m_DateFormatType = value;
                }
            }

            public static string DateSaparator
            {
                get
                {
                    return m_DateSaparator;
                }
                set
                {
                    m_DateSaparator = value;
                }
            }

            public static int Decimals
            {
                get
                {
                    return m_Decimals;
                }
                set
                {
                    m_Decimals = value;
                }
            }

            public static string DecimalSymbol
            {
                get
                {
                    return m_DecimalSymbol;
                }
                set
                {
                    m_DecimalSymbol = value;
                }
            }

            public static string DigitGroupSymbol
            {
                get
                {
                    return m_DigitGroupSymbol;
                }
                set
                {
                    m_DigitGroupSymbol = value;
                }
            }

            public static string FormatDate
            {
                get
                {
                    if (m_DateFormatType == clsOption.FormatType.DMY)
                    {
                        m_FormatDate = clsOption.FormatType.DMY.ToString().Replace("/", m_DateSaparator);
                        return m_FormatDate;
                    }
                    if (m_DateFormatType == clsOption.FormatType.MDY)
                    {
                        m_FormatDate = clsOption.FormatType.MDY.ToString().Replace("/", m_DateSaparator);
                        return m_FormatDate;
                    }
                    if (m_DateFormatType == clsOption.FormatType.YMD)
                    {
                        m_FormatDate = clsOption.FormatType.YMD.ToString().Replace("/", m_DateSaparator);
                        return m_FormatDate;
                    }
                    return m_FormatDate;
                }
                set
                {
                    m_DateFormatType = clsOption.FormatType.Custom;
                    m_FormatDate = value;
                }
            }

            public static string FormatNumber
            {
                get
                {
                    string str = "##,##0.";
                    for (int i = 0; i < m_Decimals; i++)
                    {
                        str = str + "#";
                    }
                    m_FormatNumber = str;
                    return str;
                }
                set
                {
                    m_FormatNumber = value;
                }
            }

            public static bool IsMsgBoxResult
            {
                get
                {
                    return m_IsMsgBoxResult;
                }
                set
                {
                    m_IsMsgBoxResult = value;
                }
            }

            public static bool IsQuestion
            {
                get
                {
                    return m_IsQuestion;
                }
                set
                {
                    m_IsQuestion = value;
                }
            }

            public static string StringFormat
            {
                get
                {
                    return ("{0:" + FormatNumber + "}");
                }
            }
        }

        public class System2
        {
            private static bool m_IsMsgBoxError = true;
            private static bool m_IsMsgBoxResult = true;
            private static bool m_IsQuestion = true;

            public static bool IsMsgBoxError
            {
                get
                {
                    return m_IsMsgBoxError;
                }
                set
                {
                    m_IsMsgBoxError = value;
                }
            }

            public static bool IsMsgBoxResult
            {
                get
                {
                    return m_IsMsgBoxResult;
                }
                set
                {
                    m_IsMsgBoxResult = value;
                }
            }

            public static bool IsQuestion
            {
                get
                {
                    return m_IsQuestion;
                }
                set
                {
                    m_IsQuestion = value;
                }
            }
        }
    }
}
